<? 

function drawCart($id, $a) {

	$GLOBALS['cart_total'] += ($cost = (float)$a['price'] * $a['num']);

	return "<tr>
	<td><a title=\"Удалить из корзины «$a[title]»\" class=\"button kill\" href=\"#\" onclick=\"if (confirm('Вы действительно хотите удалить «$a[title]»?')) xCart.kill($a[id]); return false;\"><span>Удалить</span></a></td>
		<td>$o $a[title]</td>
		
		<td class=\"custom_ui_roller\"><input type=\"text\" class=\"popup_num_input\" value=\"$a[num]\" readonly=\"readonly\" />
			<div class=\"ui_roller\">
				<a class=\"ui_roller roll_up cart_plus\" href=\"#\" title=\"Увеличить\" onclick=\"xCart.increase($a[id])\"><span>+1</span></a>
				<a class=\"ui_roller roll_dn cart_minus\" href=\"#\" title=\"Уменьшить\" onclick=\"xCart.decrease($a[id])\"><span>-1</span></a>
				<div class=\"clearer\"></div>
			</div>
		</td>
		
		<td>$a[price] грн</td><td>$cost грн</td></tr>";

}

function cartIterate($cart, $iterator) {
	$temp = "";
	
	foreach($cart as $id => $a) {
		$temp .= call_user_func($iterator, $id, $a);
	}
	return $temp;
}


if (sizeof($_SESSION['cart'])) {

	$temp = <<<_DaTa
		<table class="cart">
			<thead><tr><td></td><td>Наименование</td><td class="custom_ui_roller">Кол-во</td><td>Цена</td><td>Стоимость</td></tr></thead>
			<tbody>
_DaTa;

	$GLOBALS['cart_total'] = 0;
	$temp .= cartIterate($_SESSION['cart'], 'drawCart');
	$GLOBALS[cart_total] = formatPrice($GLOBALS[cart_total]);
	
	$temp .= <<<_DaTa
</tbody><thead class="compo"><tr><td colspan="4">Итого</td><td>$GLOBALS[cart_total] грн</td></tr></thead><tbody>
			</tbody>
		</table>
_DaTa;

} else {

	$temp = "<p>В корзине пусто</p>";
	
}

return str_replace('<tbody></tbody>', '', $temp);

?>